<?php
namespace Home\Controller;
use Think\Controller;
class PhotoController extends CommonController {

    //以瀑布流形式随机显示其他用户的共享相片
    public function index(){
        $this -> assign('test','图片乐分享');
        $this->display();
    }

    //实现瀑布流需要调用的ajax脚本
    public function ajaximg(){
        if (IS_AJAX) {

            /*
            //获取所有共享相册的用户信息
            select u.user_id,u.nickname,u.photo,a.albums_id from zz_user_info u join zz_albums a on u.user_id=a.user_id where albums_type=1;
            +---------+----------+---------------------------------------------+-----------+
            | user_id | nickname | photo                                       | albums_id |
            +---------+----------+---------------------------------------------+-----------+
            |      17 | Veris    | /Uploads/photo/2016-05-26/574653fb8467a.png |         2 |
            |      25 | Veris    | /Resource/default_photo.png                 |         4 |
            +---------+----------+---------------------------------------------+-----------+

            //获取所有共享相册的照片信息
            select albums_id,photos_id,photos_name,photos_zan,photos_path from zz_photos where albums_id in (select albums_id from zz_albums where albums_type=1);
            +-----------+-----------+-------------------------+------------+---------------------------------------------+
            | albums_id | photos_id | photos_name             | photos_zan | photos_path                                 |
            +-----------+-----------+-------------------------+------------+---------------------------------------------+
            |         2 |        57 | 2015-08-25_19.32.37.png |          4 | /Uploads/photo/2016-05-25/5745a173bf25f.png |
            |         2 |        58 | 2015-08-25_19.34.58.png |          2 | /Uploads/photo/2016-05-25/5745a173e915a.png |
            |         2 |        59 | 开心的柴犬               |          0 | /Uploads/photo/2016-05-25/5745aaea728e8.jpg |
            |         4 |        63 | 开心的小狗               |          0 | /Uploads/photo/2016-05-26/5746eb587608a.jpg |
            +-----------+-----------+-------------------------+------------+---------------------------------------------+

            //获取所有共享相册的照片及用户信息
            select user_id,nickname,photo,u.albums_id,photos_id,photos_name,photos_zan,photos_path,time from (select u.user_id,u.nickname,u.photo,a.albums_id from zz_user_info as u join zz_albums as a on u.user_id=a.user_id where albums_type=1) as u join (select albums_id,photos_id,photos_name,photos_zan,photos_path,time from zz_photos where albums_id in (select albums_id from zz_albums where albums_type=1)) as p on u.albums_id=p.albums_id order by photos_id desc;
            +---------+----------+---------------------------------------------+-----------+-----------+--------------------------------------------+------------+---------------------------------------------+------------+
            | user_id | nickname | photo                                       | albums_id | photos_id | photos_name                                | photos_zan | photos_path                                 | time       |
            +---------+----------+---------------------------------------------+-----------+-----------+--------------------------------------------+------------+---------------------------------------------+------------+
            |      25 | 柴犬     | /Uploads/photo/2016-05-26/5746ff4434b0e.jpg |         4 |        88 | 车票预订   客运服务   铁路客户服务中心.png |          0 | /Uploads/photo/2016-05-26/5746fca7c6200.png | 1464269991 |
            |      25 | 柴犬     | /Uploads/photo/2016-05-26/5746ff4434b0e.jpg |         4 |        63 | 开心的小狗                                 |          0 | /Uploads/photo/2016-05-26/5746eb587608a.jpg | 1464265560 |
            |      17 | Veris    | /Uploads/photo/2016-05-26/574653fb8467a.png |         2 |        59 | 开心的柴犬                                 |          1 | /Uploads/photo/2016-05-25/5745aaea728e8.jpg | 1464183530 |
            +---------+----------+---------------------------------------------+-----------+-----------+--------------------------------------------+------------+---------------------------------------------+------------+
            */

            $page=I('get.p',1,'int');   //当前页数
            $page=max(1,$page);
            $num=8;                     //显示多少条数
            $limit='limit '.($page-1)*$num.','.$num;

            //获取所有用户的共享相册信息，并按照片id降序
            $model=M();
            $result=$model->query('select user_id,nickname,photo,u.albums_id,photos_id,photos_name,photos_zan,photos_path,time from (select u.user_id,u.nickname,u.photo,a.albums_id from zz_user_info as u join zz_albums as a on u.user_id=a.user_id where albums_type=1) as u join (select albums_id,photos_id,photos_name,photos_zan,photos_path,time from zz_photos where albums_id in (select albums_id from zz_albums where albums_type=1)) as p on u.albums_id=p.albums_id order by photos_id desc '.$limit);
            $this->ajaxReturn($result);
        }
    }

    //实现添加到自己的相册中需要调用的ajax脚本
    public function ajaxcollect(){
        //这里请使用ajax访问
        // if (IS_AJAX) {}
        echo '实现添加到自己的相册中需要调用的ajax脚本!';
    }

    //实现评论相应相片需要调用的ajax脚本
    public function ajaxbb(){
        //这里请使用ajax访问
        // if (IS_AJAX) {}
        echo '实现评论相应相片需要调用的ajax脚本';
    }

}
